package com.woniuxy.amusementparkos.service.wyh.imp;

import java.math.BigDecimal;
import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.woniuxy.amusementparkos.dao.wyh.WristStrap_InfoDao;
import com.woniuxy.amusementparkos.entity.wyh.PageBean;
import com.woniuxy.amusementparkos.entity.wyh.WristStrap_Info;
import com.woniuxy.amusementparkos.service.wyh.WristStrap_InfoService;

import java_cup.internal_error;
@Service
public class WristStrap_InfoServiceImp implements WristStrap_InfoService {
	@Autowired
	WristStrap_InfoDao wristStrap_InfoDao ;
	
	
	//根据info——id查询
	@Override
	public WristStrap_Info getByInfoId(int info_id) {
		
		return wristStrap_InfoDao.getByInfoId(info_id);
	}

	
	//根据腕带id查询
	@Override
	public List<WristStrap_Info> getByWristStrapId(String wriststrp_id) {
		
		return wristStrap_InfoDao.getByWristStrapId(wriststrp_id);
	}
	
	
	//查询所有腕带信息
	@Override
	public WristStrap_Info getAllWristStrapInfo() {
		
		return wristStrap_InfoDao.getAllWristStrapInfo();
	}

	//新增腕带信息
	@Override
	public void insert(WristStrap_Info wristStrap_Info) {
		
		wristStrap_InfoDao.insert(wristStrap_Info);
	}

	//新增腕带信息并且返回腕带识别号info_id
	@Override
	public int insertBackInfoid(WristStrap_Info wristStrap_Info) {
		
		//新插入腕带数据
		wristStrap_InfoDao.insert(wristStrap_Info);
		
		
		
		return wristStrap_InfoDao.getCurrentInfoId();
	}


	//修改变动余额
	@Override
	public void changeBalacne(int info_id,BigDecimal newbalance) {
		
		wristStrap_InfoDao.updateBalance(info_id, newbalance);
	}

	//根据腕带编号wriststrp_id 查询该正在使用状态的信息；
	
	@Override
	public WristStrap_Info queryByWristStrap_Id(String wriststrp_id) {
		// TODO Auto-generated method stub
		return wristStrap_InfoDao.queryByWristStrap_Id(wriststrp_id);
	}

	//根据条件查询 腕带编号， 电话号码，腕带使用状态
	@Override
	public PageBean<WristStrap_Info> selectByCondition(WristStrap_Info wristStrap_Info,Integer pageindex
			,Integer size) {
		
		//创建分页bean
		PageBean<WristStrap_Info> pageBean = new PageBean<WristStrap_Info>();
		
		if(size==null) {
			//分页数据长度
			size=10;
		}
		
			
		//获取分页数据
			List<WristStrap_Info> selectByCondition = wristStrap_InfoDao.selectByCondition(wristStrap_Info,(pageindex-1)*10,size);
		
		//获取该条件数据总数
			int count = (int) wristStrap_InfoDao.selectCountByCondition(wristStrap_Info);
			
		//装配分页bean
			pageBean.setBeanList(selectByCondition);
			pageBean.setPageSize(size);
			pageBean.setPageIndex(pageindex);
			pageBean.setTotalRecord(count);
			//设置总页数
			pageBean.setTotalPage(pageBean.getTotalPage());
			
			System.out.println(pageBean);
		return pageBean;
	}

	
	//根据腕带信息查询正在使用状态的腕带！
	@Override
	public WristStrap_Info getWorkStateWristStrap(String wriststrp_id) {
		
		
		
		return wristStrap_InfoDao.getWorkStateWristStrap(wriststrp_id);
	}


	@Override
	public void updateWindupMessage(WristStrap_Info wristStrap_Info) {
		wristStrap_InfoDao.updateWindupMessage(wristStrap_Info);
		
	}

	@Override
	public int updateAllWindupMessage(WristStrap_Info wristStrap_info) {
		return this.wristStrap_InfoDao.updateAllWindupMessage(wristStrap_info);
	}

	//执行更换业务   更换腕带号；
	@Override
	public void doreplace(String oldwriststrapid, String newwriststrapid) {
		//更换腕带编号
		wristStrap_InfoDao.repalceWristStrap(oldwriststrapid, newwriststrapid);

	}

	@Override
	public void lossAndUnlock(String wriststrp_id, int oldinfo_state, int newinfo_state) {

		wristStrap_InfoDao.lossAndUnlock(wriststrp_id, oldinfo_state, newinfo_state);
	}

}
